package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.RolesEnums;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFourConfig;
import com.ruoyi.system.service.ISysFourConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 北斗系统参数配置Controller
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@RestController
@RequestMapping("/system/four/config")
public class SysFourConfigController extends BaseController
{
    @Autowired
    private ISysFourConfigService sysFourConfigService;

    /**
     * 查询北斗系统参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFourConfig sysFourConfig)
    {

        SysUser user = getLoginUser().getUser();
        Long roleId = user.getRoleId();
        String roleKey = RolesEnums.getRoleKeyByRoleId(roleId);
        // 运输公司管理员
        if(RolesEnums.YUN_SHU_ADMIN.getRoleKey().equals(roleKey)){
            sysFourConfig.setSysUserId(user.getUserId()+"");
        }
        startPage();
        List<SysFourConfig> list = sysFourConfigService.selectSysFourConfigList(sysFourConfig);
        return getDataTable(list);
    }



    /**
     * 查询北斗系统参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/configList")
    public TableDataInfo configList(SysFourConfig sysFourConfig)
    {

        SysUser user = getLoginUser().getUser();
//        Long roleId = user.getRoleId();
//        String roleKey = RolesEnums.getRoleKeyByRoleId(roleId);
//        // 运输公司管理员
//        if(RolesEnums.YUN_SHU_ADMIN.getRoleKey().equals(roleKey)){
//            sysFourConfig.setSysUserId(user.getUserId()+"");
//        }
        sysFourConfig.setSysUserId(user.getUserId()+"");
        startPage();
        List<SysFourConfig> list = sysFourConfigService.selectSysFourConfigList(sysFourConfig);
        return getDataTable(list);
    }

    /**
     * 导出北斗系统参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "北斗系统参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFourConfig sysFourConfig)
    {
        List<SysFourConfig> list = sysFourConfigService.selectSysFourConfigList(sysFourConfig);
        ExcelUtil<SysFourConfig> util = new ExcelUtil<SysFourConfig>(SysFourConfig.class);
        util.exportExcel(response, list, "北斗系统参数配置数据");
    }

    /**
     * 获取北斗系统参数配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysFourConfigService.selectSysFourConfigById(id));
    }

    /**
     * 新增北斗系统参数配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "北斗系统参数配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFourConfig sysFourConfig)
    {
        return toAjax(sysFourConfigService.insertSysFourConfig(sysFourConfig));
    }

    /**
     * 修改北斗系统参数配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "北斗系统参数配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFourConfig sysFourConfig)
    {
        return toAjax(sysFourConfigService.updateSysFourConfig(sysFourConfig));
    }

    /**
     * 删除北斗系统参数配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "北斗系统参数配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysFourConfigService.deleteSysFourConfigByIds(ids));
    }
}
